home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / applic / ncsa / Mac / Telnet2.6 / prerelease / d3 / Telnet2.6.1d3.src.sit.hqx / Telnet 2.6.1d3 source / source / tek / tekrgmac.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-19  |  12.6 KB  |  589 lines

  1. /*
  2. rgmac.c by Gaige B. Paulsen
  3.   spawned from rgp.c by Aaron Contorer for NCSA
  4. Copyright 1987, board of trustees, University of Illinois
  5.  
  6. Routines for Macintosh Window output.  
  7. */
  8.  
  9. #ifdef MPW
  10. #pragma segment TEKMAIN
  11. #endif
  12.  
  13. #include <stdio.h>
  14. #include <String.h>
  15. #include <Packages.h>
  16.  
  17. #include "tekrgmac.proto.h"
  18. #include "TelnetHeader.h"
  19. #include "maclook.proto.h"
  20. #include "vgtek.proto.h"
  21. #include "mydnr.proto.h"
  22. #include "rsmac.proto.h"
  23. #include "netevent.proto.h"
  24. #include "rg0.proto.h"
  25. #include "rgmp.proto.h"
  26. #include "InternalEvents.h"
  27. #include "tekdefs.h"        /* NCSA: sb - all the TEK defines are now here */
  28.  
  29. #define TEK_DEBUG1
  30. #ifdef    TEK_DEBUG1
  31. #include "debug.h"
  32. #define    TEK_DEBUG_PRINT(x)    putln(x)
  33. char    TEK_DEBUG_STRING    [512];
  34. #else
  35. #define    TEK_DEBUG(x)
  36. #endif
  37.  
  38. /*--------------------------------------------------------------------------*/
  39. /* Some variable definitions are needed before we give the code                */
  40. /*                                                                             */
  41. /*--------------------------------------------------------------------------*/
  42.  
  43. long    RGMlastclick;
  44. short    RGMcolor[]=
  45.     { 30,            /* black */
  46.       33,            /* white */
  47.       205,            /* red */
  48.       341,            /* green */
  49.       409,            /* blue */
  50.       273,            /* cyan */
  51.       137,            /* magenta */
  52.       69            /* yellow */
  53.       };
  54.  
  55. struct    RGMwindows *RGMwind[ MAXWIND ];
  56.  
  57. char    *RGMdevname(void)
  58. {
  59.     return("Macintosh Windows");
  60. }
  61.  
  62. short    RGMnewwin(void)
  63. {
  64.     short    i = 0;
  65.  
  66.     while ((i < MAXWIND) && (RGMwind[i]->inuse)) i++;
  67.  
  68.     if (i >= MAXWIND) return(-1);
  69.  
  70.     RGMwind[i]->wind = GetNewWindow(256, NULL, kInFront);
  71.     if (RGMwind[i]->wind == 0L) return(-1);
  72.  
  73.     ((WindowPeek)RGMwind[i]->wind)->windowKind = WIN_TEK;
  74.     
  75.     RGMwind[i]->vg = -1;                /* BYU */
  76.     RGMwind[i]->vs = -1;                /* BYU */
  77.     RGMwind[i]->xorigin = 0;
  78.     RGMwind[i]->yorigin = 0;
  79.     RGMwind[i]->xscale  = WINXMAX;    /* BYU LSC - need the "W" here */
  80.     RGMwind[i]->yscale  = WINYMAX;    /* BYU LSC - need the "W" here */
  81.     RGMwind[i]->width   = 400;        /* BYU LSC - was 256 (size of old window resource */
  82.     RGMwind[i]->height  = 300;        /* BYU LSC - was 342 (size of old window resource */
  83.     RGMwind[i]->inuse   = TRUE;
  84.     RGMwind[i]->ingin   = 0;        /* BYU LSC */
  85.  
  86.     ValidRect(&RGMwind[i]->wind->portRect);  
  87.  
  88.     return(i);
  89. }
  90.  
  91. void    RGMinit(void)
  92. {
  93.     short    i;
  94.     for (i = 0; i < MAXWIND; i++)
  95.         RGMwind[i]->inuse = 0;
  96. }
  97.  
  98. short    RGMgin(short w)
  99. {
  100.     if (RGsetwind(w)) return(-1);
  101.  
  102.     setgraphcurs();
  103.     RGMwind[w]->ingin=1;
  104. }
  105.  
  106. short    RGMpencolor(short w, short color)
  107. {
  108.     if (RGsetwind(w) ) return(-1);
  109.     ForeColor((long) RGMcolor[color] );
  110. #ifdef    TEK_DEBUG_1
  111.     sprintf(TEK_DEBUG_STRING, "TEK: Setting pen color to %d", color);
  112.     putln(TEK_DEBUG_STRING);
  113. #endif
  114.  
  115. }
  116.  
  117. short    RGMclrscr(short w)
  118. {    
  119.     if (RGsetwind(w) ) return(-1);
  120.     PaintRect(&RGMwind[w]->wind->portRect);
  121.     TEK_DEBUG_PRINT("TEK: Clearing screen");                    
  122. }    
  123.  
  124. short    RGMclose(short w)
  125. {
  126.     if (RGsetwind(w) ) return(-1);
  127.  
  128.     DisposeWindow(RGMwind[w]->wind);
  129.     RGMwind[w]->inuse  = FALSE;
  130. }
  131.  
  132. short    RGMpoint(short w, short x, short y)
  133. {
  134.     if (RGsetwind(w) ) return(-1);
  135.  
  136.     MoveTo(x,y);
  137.     LineTo(x,y);
  138.  
  139. short    RGMdrawline(short w, short x0, short y0, short x1, short y1)
  140. {
  141.     long    xl0, yl0, xl1, yl1;
  142.     
  143.     if (RGsetwind(w) )
  144.         return(-1);
  145.  
  146.     xl0 = ((long)x0 * RGMwind[w]->width) / INXMAX;
  147.     yl0 = (long)RGMwind[w]->height - (((long)y0 * RGMwind[w]->height) / INYMAX);
  148.     xl1 = ((long)x1 * RGMwind[w]->width) / INXMAX;
  149.     yl1 = (long)RGMwind[w]->height - (((long)y1 * RGMwind[w]->height) / INYMAX);
  150.  
  151.     MoveTo((short)xl0, (short)yl0);
  152.     LineTo((short)xl1, (short)yl1);
  153. }
  154.  
  155. void    RGMinfo(short w, short v, short a, short b, short c, short d)
  156. {
  157.     UNUSED_ARG(a)
  158.     UNUSED_ARG(b)
  159.     UNUSED_ARG(c)
  160.     UNUSED_ARG(d)
  161.     RGMwind[w]->vg=v;
  162. }
  163.  
  164. void    RGMpagedone(short w)
  165. {
  166.     UNUSED_ARG(w)
  167. }
  168.  
  169. void    RGMdataline(short w, short data, short count)
  170. {
  171.     UNUSED_ARG(w)
  172.     UNUSED_ARG(data)
  173.     UNUSED_ARG(count)
  174. }
  175.  
  176.  
  177. void    RGMcharmode(short w, short rotation, short size)
  178. {
  179.     UNUSED_ARG(w)
  180.     UNUSED_ARG(rotation)
  181.     UNUSED_ARG(size)
  182. }
  183.  
  184. void    RGMgmode(void)
  185. {}
  186.  
  187. void    RGMtmode(void)
  188. {}
  189.  
  190. void    RGMshowcur(void)
  191. {
  192. }
  193.  
  194. void    RGMlockcur(void)
  195. {
  196. }
  197.  
  198. void    RGMhidecur(void)
  199. {
  200. }
  201.  
  202. void    RGMbell(short w)
  203. {
  204.     UNUSED_ARG(w)
  205. }
  206.  
  207. void    RGMuncover(short w)
  208. {
  209.     UNUSED_ARG(w)
  210. }
  211.  
  212. short    RGMoutfunc(short (*f )())
  213. {
  214.     UNUSED_ARG(f)
  215.     return(0);    // Unused
  216. }
  217.  
  218. Boolean RGMalloc(void)        /* BYU - allocate this structure to save global space */
  219. {
  220.     short i;
  221.     for(i=0; i<MAXWIND; i++) {        /* BYU */
  222.         RGMwind[i] = (struct RGMwindows *) NewPtrClear(sizeof(struct RGMwindows));    /* BYU */
  223.         if (RGMwind[i]) {                        /* BYU */
  224.             RGMwind[i]->wind = (GrafPtr) 0;        /* BYU */
  225.             RGMwind[i]->id = 'RGMW';
  226.             RGMwind[i]->vg = -1;                /* BYU - necessary */
  227.             RGMwind[i]->vs = -1;                /* BYU */
  228.             RGMwind[i]->inuse = 0;                /* BYU - necessary */
  229.         } else                                     /* BYU */
  230.             return (TRUE);                /* BYU - insufficient memory */
  231.     }
  232.     return(FALSE);
  233. }
  234.  
  235. short    RGsetwind(short dnum)
  236. {
  237.     if (dnum<0 || dnum>=MAXWIND) return(-1);
  238.  
  239.     if (!RGMwind[dnum]->inuse) return(-1);
  240.  
  241.     SetPort( RGMwind[dnum]->wind);
  242.     return(0);
  243. }
  244.  
  245. short    RGfindbyVG(short vg)
  246. {
  247.     short    i = 0;
  248.  
  249.     while ((i < MAXWIND) && ((!RGMwind[i]->inuse) || (RGMwind[i]->vg != vg)))
  250.         i++;
  251.     if (i >= MAXWIND) return(-1);
  252.     return(i);
  253. }
  254.  
  255. short    RGattach(short vg, short virt, char *name, short TEKtype)
  256. {
  257.     short            dnum;
  258.     unsigned long    time;
  259.     char            myname[256],ts[256];
  260.  
  261.     if ((dnum = RGfindbyVG(vg)) < 0) return(-1);
  262.  
  263.     RGMwind[dnum]->vs = virt;
  264.     RGMwind[dnum]->name = (unsigned char *) NewPtrClear((long) 256);        /* BYU LSC */
  265.  
  266.     if (RGMwind[dnum]->name == 0L) return(-2);
  267.  
  268.     myname[0] = 'Ñ';
  269.     if (TEKtype)
  270.         strcpy(&myname[1], "[4105] ");
  271.     else
  272.         strcpy(&myname[1], "[4014] ");
  273.         
  274.     strncpy(&myname[strlen(myname)],name,120);
  275.  
  276.     GetDateTime(&time);
  277.     IUTimeString(time,FALSE,(StringPtr) ts);        /* BYU LSC - Put time in the temp string */
  278.     p2cstr((StringPtr)ts);                                            /* BYU LSC */
  279.  
  280.     strncat(myname,"  ",2);                /* BYU - was 4 - Space, please */
  281.     strncat(myname,ts,64);                /* BYU - Place the time string at the end */
  282.     strcpy((char *) RGMwind[dnum]->name,myname);    /* BYU LSC */
  283.  
  284.     if (RGMwind[dnum]->wind != (GrafPtr) 0) {    /* BYU LSC */
  285.         c2pstr(myname);                            /* BYU LSC */
  286.         SetWTitle(RGMwind[dnum]->wind,(StringPtr)myname);    /* BYU LSC */
  287.     }
  288.  
  289.     return(0);
  290. }
  291.  
  292.  
  293. short    RGdetach( short vg)
  294. {
  295.         short    dnum;            /* BYU */
  296.         char    myname[256];            /* BYU LSC */
  297.  
  298.     if ((dnum = RGfindbyVG(vg)) < 0) return(-1);        /* BYU */
  299.     if (dnum >= MAXWIND)  return(-1);                    /* BYU */
  300.  
  301.     if (RGMwind[dnum]->vs != -1) {                                     /* BYU */
  302.         if (RGMwind[dnum]->wind != (GrafPtr) 0) {                    /* BYU */
  303. #if 1
  304.             strncpy((char *) RGMwind[dnum]->name,                /* BYU LSC */
  305.                     (char *) &RGMwind[dnum]->name[1],255);        /* BYU LSC */
  306.             strncpy(myname, (char *) RGMwind[dnum]->name,256);    /* BYU LSC */
  307.             c2pstr(myname);                                        /* BYU LSC */
  308.             SetWTitle(RGMwind[dnum]->wind,(StringPtr)myname);                /* BYU LSC */
  309. #else
  310.             strncpy((char *) RGMwind[dnum]->name,                /* BYU LSC */
  311.                     (char *) &RGMwind[dnum]->name[1],255);        /* BYU LSC */
  312.             SetWTitle(RGMwind[dnum]->wind,RGMwind[dnum]->name);    /* BYU LSC */
  313. #endif
  314.         }                            /* BYU */
  315.     }                                /* BYU */
  316.     return(0);                        /* BYU */
  317. }
  318.  
  319. short    RGfindbywind( GrafPtr wind)
  320. {
  321.     short    i = 0;
  322.  
  323.     while ((i < MAXWIND) && ((!RGMwind[i]->inuse) || (RGMwind[i]->wind != wind)))
  324.         i++;
  325.     if (i >= MAXWIND) return(-1);
  326.     return(i);
  327. }
  328.  
  329. short    RGupdate( GrafPtr wind)
  330. {
  331.     short    i = 0,
  332.             done;
  333.  
  334.     if ((i = RGfindbywind(wind)) < 0)
  335.         return(-1);
  336.  
  337.     SetPort(wind);
  338.     BeginUpdate(wind);
  339.  
  340.     VGstopred(RGMwind[i]->vg);
  341.     VGpage(RGMwind[i]->vg);
  342.     done = VGpred(RGMwind[i]->vg,RGMwind[i]->vg);
  343.  
  344.     EndUpdate(wind);
  345.     if (!done)
  346.         netputevent(USERCLASS,RG_REDRAW,RGMwind[i]->vg,0);
  347.     return(done);
  348. }
  349.  
  350. short    RGsupdate( short i)
  351. {
  352.     short    rg;
  353.  
  354.     rg = RGfindbyVG(i);
  355.  
  356.     if (rg < 0) return(0);
  357.     SetPort(RGMwind[rg]->wind);
  358.     if (!VGpred(RGMwind[rg]->vg,RGMwind[rg]->vg))
  359.     {
  360.         netputevent(USERCLASS,RG_REDRAW,i,0);
  361.     }
  362.     else
  363.         return(1);
  364.     return(0);
  365. }
  366.  
  367. short    RGgetVG(GrafPtr wind)
  368. {
  369.     short    i;
  370.  
  371.     i = RGfindbywind(wind);
  372.  
  373.     return(RGMwind[i]->vg);
  374. }
  375.  
  376. short    RGgetdnum(GrafPtr wind)
  377. {
  378.     return(RGfindbywind(wind));
  379. }
  380.  
  381. short    RGgetVS(short dnum)
  382. {
  383.     return(RGMwind[dnum]->vs);
  384. }
  385.  
  386. short    inSplash(Point *p1, Point *p2)
  387. {
  388.     if ((p1->h - p2->h > 3) || (p2->h - p1->h > 3))
  389.         return(0);
  390.     if ((p1->v - p2->v > 3) || (p2->v - p1->v > 3))
  391.         return(0);
  392.  
  393.     return(1);
  394. }
  395.  
  396. void VidSync( void)
  397. {
  398.     long    a;
  399.     a = TickCount();            /* BYU LSC */
  400.     while (a == TickCount())
  401.         /* loop*/;    /* BYU LSC */
  402. }
  403.  
  404. void RGmousedown
  405.   (
  406.     GrafPtr wind,
  407.     Point *wherein
  408.   )
  409. {
  410.     unsigned long    lx,ly;        /* NCSA: SB */
  411.     char            thispaceforent[6];
  412.     short            i;
  413.     Point            where;
  414.     char            dum[32];
  415.  
  416.     where = *wherein;
  417.     if ((i = RGfindbywind(wind)) < 0)
  418.         return;
  419.  
  420.     if (!RGMwind[i]->ingin)
  421.     {
  422.     Point    anchor,current,last;
  423. #if 0                            /* BYU LSC - was "#ifndef MPW" */
  424.     long    TickCount();
  425. #endif MPW
  426.     long    tc;
  427.     short    x0,y0,x1,y1;
  428.     Rect    rect;
  429.     
  430.         SetPort(wind);
  431.     
  432.         last  = where;
  433.         current = where;
  434.         anchor = where;
  435.     
  436.         PenPat(PATTERN(qd.gray));    
  437.         PenMode(patXor);
  438.     
  439.         SetRect(&rect,0,0,0,0);
  440.     
  441.         while (StillDown())
  442.         {
  443.             GetMouse(¤t);
  444.             if (inSplash(¤t,&anchor)) continue;
  445.             tc = TickCount();
  446.             while(TickCount() == tc)
  447.                 /* loop */;
  448.             VidSync();
  449.             FrameRect(&rect);
  450.     
  451.             if (anchor.v < current.v)
  452.             {
  453.                 rect.top = anchor.v;
  454.                 rect.bottom = current.v;
  455.             }
  456.             else
  457.             {
  458.                 rect.top = current.v;
  459.                 rect.bottom = anchor.v;
  460.             }
  461.     
  462.             if (anchor.h < current.h)
  463.             {
  464.                 rect.left = anchor.h;
  465.                 rect.right = current.h;
  466.             }
  467.             else
  468.             {
  469.                 rect.right = anchor.h;
  470.                 rect.left = current.h;
  471.             }
  472.     
  473.             FrameRect(&rect);
  474.             last = current;
  475.         }
  476.     
  477.         FrameRect(&rect);
  478.  
  479.         PenPat(PATTERN(qd.black));    
  480.         PenMode(patCopy);
  481.  
  482.         if (!inSplash(&anchor,¤t))
  483.         {
  484.             x0 = (short) ((long) rect.left * RGMwind[i]->xscale / RGMwind[i]->width );
  485.             y0 = (short) (RGMwind[i]->yscale -
  486.                     (long) rect.top * RGMwind[i]->yscale / RGMwind[i]->height);
  487.             x1 = (short) ((long) rect.right * RGMwind[i]->xscale / RGMwind[i]->width);
  488.             y1 = (short) (RGMwind[i]->yscale -
  489.                     (long) rect.bottom * RGMwind[i]->yscale / RGMwind[i]->height);
  490.             x1 = (x1 < x0+2) ? x0 + 4 : x1;
  491.             y0 = (y0 < y1+2) ? y1 + 4 : y0;
  492.  
  493.             VGzoom( i,
  494.                     x0 + RGMwind[i]->xorigin,
  495.                     y1 + RGMwind[i]->yorigin,
  496.                     x1 + RGMwind[i]->xorigin,
  497.                     y0 + RGMwind[i]->yorigin);
  498.  
  499.             VGpage(RGMwind[i]->vg);
  500.  
  501.             RGMwind[i]->xscale  = x1 - x0;
  502.             RGMwind[i]->yscale  = y0 - y1;
  503.             RGMwind[i]->xorigin = x0 + RGMwind[i]->xorigin;
  504.             RGMwind[i]->yorigin = y1 + RGMwind[i]->yorigin;
  505.  
  506.             while(!VGpred(RGMwind[i]->vg,RGMwind[i]->vg))
  507.                 Stask();
  508.             RGMlastclick = 0L;
  509.         }
  510.         else
  511.         {
  512.             if (RGMlastclick && ((RGMlastclick + GetDblTime()) > TickCount()))
  513.             {
  514.                 RGMwind[i]->xscale  = WINXMAX;    /* BYU LSC - need the "W" here */
  515.                 RGMwind[i]->yscale  = WINYMAX;    /* BYU LSC - need the "W" here */
  516.                 RGMwind[i]->xorigin = 0;
  517.                 RGMwind[i]->yorigin = 0;
  518.  
  519.                 VGzoom(i,0,0,WINXMAX-1,WINYMAX-1);    /* BYU LSC - need the "W" here */
  520.                 VGpage( RGMwind[i]->vg);
  521.                 while(!VGpred(RGMwind[i]->vg,RGMwind[i]->vg))
  522.                     Stask();
  523.                 RGMlastclick = 0L;
  524.             }
  525.             else RGMlastclick = TickCount();
  526.         }
  527.         return;
  528.     
  529.     }
  530.     
  531.     /* NCSA: SB */
  532.     /* NCSA: SB - These computations are being truncated and turned into signed ints. */
  533.     /* NCSA: SB - Just make sure everything is cast correctly, and were fine */
  534.     
  535.     lx = ((unsigned long)RGMwind[i]->xscale * (unsigned long)where.h)     /* NCSA: SB */
  536.             / (unsigned long)RGMwind[i]->width;                             /* NCSA: SB */
  537.     ly = (unsigned long)RGMwind[i]->yscale -                             /* NCSA: SB */
  538.         ((unsigned long)RGMwind[i]->yscale * (unsigned long)where.v) / (unsigned long)RGMwind[i]->height; /* NCSA: SB */
  539.  
  540.     VGgindata(RGMwind[i]->vg,(unsigned short) lx,(unsigned short)ly,' ',thispaceforent);    /* NCSA: SB */
  541.  
  542. #if 0                                                    /* BYU LSC - not needed */
  543. sprintf(dum,"GIN i: %d, vs: %d\015",i,RGMwind[i]->vs);    /* BYU 2.4.18 - changed \n to \015 */
  544. putln(dum);
  545. #endif                                                    /* BYU LSC - not needed */
  546.  
  547.     RSsendstring(RGMwind[i]->vs,thispaceforent,5);
  548.     sprintf(dum," \r\n");
  549.     RSsendstring(RGMwind[i]->vs,dum,3);
  550.     
  551.  
  552.     /*    RGMwind[i]->ingin = 0; */
  553.     unsetgraphcurs();
  554.     RGMlastclick = TickCount();
  555. }
  556.  
  557.  
  558. /*--------------------------------------------------------------------------*/
  559. /* NCSA: SB - RGMgrowme                                                        */
  560. /* This allows the TEK window to be grown like any other real window.        */
  561. /* The grow box is not shown on the screen, but it acts accordingly     - SMB    */
  562. /*--------------------------------------------------------------------------*/
  563. void    RGMgrowme(short myRGMnum,GrafPtr window, long *where, short modifiers)
  564. {
  565.     UNUSED_ARG(modifiers)
  566.     long size;
  567.     Rect SizRect;
  568.  
  569.     SetRect(&SizRect, 50, 50, 1500, 1500);            /* NCSA: SB - max size - arbitrary */
  570.  
  571.     if (where)
  572.     {        
  573.         size = GrowWindow(window, *(Point *) where, &SizRect);    
  574.         if (size != 0L)
  575.             {
  576.             SizeWindow(window, size & 0xffff, (size >> 16) & 0xffff, FALSE);
  577.             RGMwind[myRGMnum]->width   = window->portRect.right - window->portRect.left;        
  578.             RGMwind[myRGMnum]->height  = window->portRect.bottom - window->portRect.top;         
  579.             VGpage(RGMwind[myRGMnum]->vg);
  580.             InvalRect(&window->portRect);
  581.             RGupdate(window);
  582.             }
  583.         else
  584.             return;                            /* user skipped growing */
  585.     }
  586. }
  587.  
  588.